﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Billing.Win;
using Billing.DataObjects;
using System.Linq;
using Infragistics.Win;
using Billing.WindowsBase;
using System.Linq;
namespace Billing.Transactions
{
    public partial class CorrectionTransactionForm : Billing.Transactions.TransactionBase
    {
        public CorrectionTransactionForm()
        {
            InitializeComponent();
        }

        private void CorrectionTransactionForm_Load(object sender, EventArgs e)
        {
            //this.AddNewHeader();

        }
        public override void OnSetHeaderDefaults(Billing.DataObjects.Header header)
        {
            header.Description = "test";
            header.HeaderType = (from i in this.BillingDataContext.HeaderTypes
                                 where i.ID == 1
                                 select i).First();
            base.OnSetHeaderDefaults(header);
        }

        private void ultraGrid2_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
        {
           

            if (e.Cell.Column.Key.ToLower() == "item")
            {
                ItemsForm frm = new ItemsForm();
                frm.AllowSelect = true;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    e.Cell.Value = this.BillingDataContext.ItemSelectByID(frm.SelectedObjects[0].Value as short?).First();
                }
            }
            else if (e.Cell.Column.Key.ToLower() == "tax")
            {
              TaxesForm  frm = new TaxesForm();
                frm.AllowSelect = true;
                frm.BillingDataContext = this.BillingDataContext;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    e.Cell.Value = frm.SelectedObjects[0].CurrentObject;
                }
            }
            else if (e.Cell.Column.Key.ToLower() == "account")
            {
                AccountsSelectionForm frm = new AccountsSelectionForm();
              // ClientsSelectionForm  frm = new ClientsSelectionForm();
                frm.AllowSelect = true;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    e.Cell.Value = (from i in this.BillingDataContext.Accounts
                                    where i.ID == (long)frm.SelectedObjects[0].Value
                                    select i).First();
                }
            }
        }

    }
}
